﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace DBFirstDemo.Models
{
    public partial class EFCoreDemoContext : DbContext
    {
        public virtual DbSet<Credit> Credit { get; set; }
        public virtual DbSet<People> People { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
                optionsBuilder.UseSqlServer(@"Server=192.168.56.101; Database=EFCoreDemo;Persist Security Info=True;User ID=sa;password=12345;");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Credit>(entity =>
            {
                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.Course)
                    .HasMaxLength(255)
                    .IsUnicode(false);

                entity.Property(e => e.PeopleId).HasColumnName("PeopleID");

                entity.Property(e => e.Score).HasColumnType("decimal(18, 0)");

                entity.HasOne(d => d.People)
                    .WithMany(p => p.Credit)
                    .HasForeignKey(d => d.PeopleId)
                    .HasConstraintName("PeopleID");
            });

            modelBuilder.Entity<People>(entity =>
            {
                entity.Property(e => e.Id).HasColumnName("ID");

                entity.Property(e => e.Name)
                    .HasMaxLength(255)
                    .IsUnicode(false);

                entity.Property(e => e.Sex)
                    .HasMaxLength(255)
                    .IsUnicode(false);
            });
        }
    }
}
